﻿using ET.CommonLibrary.Configurations;
using ET.CommonLibrary.Environment;
using ET.CommonLibrary.EventAggregator;
using ET.CommonLibrary.Log;
using System;

namespace ET.Score.SharedLibrary
{
    public static class EnvironmentContext
    {
        /// <summary>
        /// 设置新的日志器实例
        /// </summary>
        /// <param name="logger"></param>
        public static void SetLogger(ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");
            theLogger = logger;
        }

        public static void SetAppSettings(IAppSettings appSettings)
        {
            if (appSettings == null) 
                throw new ArgumentNullException("appSettings");
            theAppSettings = appSettings;
        }

        public static void SetDateTime(IDateTime dateTime)
        {
            if (dateTime == null)
                throw new ArgumentNullException("dateTime");

            theDateTime = dateTime;
        }

        // 当前实现里Logger属性永不返回null
        private static ILogger theLogger = EmptyLogger.Default;
        private static IAppSettings theAppSettings = new LocalAppSettings();
        private static IDateTime theDateTime = new SystemDateTime();
        private static ITopicEventAggregator theEventAggregator = new TopicEventAggregator();

        /// <summary>
        /// 获取环境日志器实例
        /// </summary>
        public static ILogger Logger
        {
            get { return theLogger; }
        }

        /// <summary>
        /// 获取环境应用程序配置实例
        /// </summary>
        public static IAppSettings AppSettings
        {
            get { return theAppSettings; }
        }

        public static IDateTime DateTime
        {
            get { return theDateTime; }
        }

        /// <summary>
        /// 获取环境主题事件聚合器
        /// </summary>
        public static ITopicEventAggregator TopicEventAggregator
        {
            get { return theEventAggregator; }
        }
    }
}
